import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';

export default {
  name: 'aread',
  components: {},
  data () {
    return {
      siteId: '',
      studentId: '',
      openId: '',
      userName: '',
      userPass: '',
      idCardNeeds: false,
      placeholderText: '请输入学员姓名',
      areaList: [],
      showArea: false

    }
  },
  mounted () {
    let _this = this
    _this.oauth()
    let siteId = window.sessionStorage.getItem("siteId")
    http.post(CONSTANT.ORGDICTLIST, {
      orgId: siteId,
      type: 'edu_business_rea'
    }, (res0) => {
      console.log('quyu', res0)
      let res = res0.data
      http.post(CONSTANT.SETTING, {
        orgId: siteId
      }, (res2) => {
        let setting = res2.data.initData.setting
        window.sessionStorage.setItem('setId', setting.id)
        window.sessionStorage.setItem('isStudBack', setting.isStudBack)
        window.sessionStorage.setItem('wechatFees', setting.wechatFees)
        window.sessionStorage.setItem('isNetApply', setting.isNetApply)
        window.sessionStorage.setItem('isChangeClass', setting.isChangeClass)
        window.sessionStorage.setItem('classNoFlag', setting.classNoFlag)
        window.sessionStorage.setItem('wechatModelId', setting.wechatModelId)
        window.sessionStorage.setItem('beginTime', setting.beginTime)
        window.sessionStorage.setItem('endTime', setting.endTime)
        window.sessionStorage.setItem('randomTime', setting.randomTime)
        if (res.length == 1) {
          window.sessionStorage.setItem("areaId",res[0].value)
          window.sessionStorage.setItem("areaName",res[0].label)
          this.$router.push({
            path: '/Hello',
            query: {
              areaId: res[0].value,
              areaName: res[0].label
            }
          })
        } else {
          if (siteId == 'FF80808133078F7601330B5AE25E007C') {
            for (var i = 0;i < res.length;i++) {
              if (res[i].label == '济南市青少年宫') {
                _this.areaList.push(res[i])
              }
            }
          } else {
            _this.areaList = res
          }
          _this.showArea = true
        }
      })
    })
  },
  methods: {
    oauth() {
      //var s = 'http://txzfzx.hztangong.com/zfzx/wx/index.html?siteId=2C9146A12760F52A01276124EFB90016&wxAvatar=http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLzWQgqxY3kMPxyWnNric9AgX4iayCB7TnRfibQs4sQ37RnU4m85vo5EbAWPDrB07XVSRltXibVOdibDBQ/132&appId=wx748e40bf9deaa2d0&payOpen=1&studentId=27C53C7D71FB7DE0E0530100007F6947&studentName=%E9%BB%84%E7%8E%89%E6%9E%97&openId=oXZJV0sllFw5QfHXknvBBMMxZx5M#/area';
      //var s = 'http://txzfzx.hztangong.com/zfzx/wx/index.html?siteId=00006e72043a7f7243629eb4e1904f42c53f&wxAvatar=http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLzWQgqxY3kMPxyWnNric9AgX4iayCB7TnRfibQs4sQ37RnU4m85vo5EbAWPDrB07XVSRltXibVOdibDBQ/132&appId=wx748e40bf9deaa2d0&payOpen=1&studentId=27C53C7D71FB7DE0E0530100007F6947&studentName=%E9%BB%84%E7%8E%89%E6%9E%97&openId=oXZJV0sllFw5QfHXknvBBMMxZx5M#/area';
      // var s = 'http://txzfzx.hztangonoging.com/zfzx/wx/index.html?siteId=2C9146A12760F52A01276124EFB90016&wxAvatar=http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLzWQgqxY3kMPxyWnNric9AgX4iayCB7TnRfibQs4sQ37RnU4m85vo5EbAsMGrnZnljYiaWic8icyR8RssQ/132&appId=wx748e40bf9deaa2d0&payOpen=true,1,2&userType=0&00000fa9556f77994b769fb8488e47126de8&studentName=%E9%BB%84%E7%8E%89%E6%9E%97&openId=oXZJV0sllFw5QfHXknvBBMMxZx5M#/area';
      var openId = window.sessionStorage.getItem('openId')
      if (openId == null || openId == '' || openId == 'undefined') {
        var s = window.location.href
        var arr = s.split('?')
        var url = arr[1]
        var theRequest = new Object()
        var strs = url.split('&')
        for (var i = 0; i < strs.length; i++) {
          var content = strs[i].split('=')
          theRequest[content[0]] = content[1]
        }
        if (theRequest.openId == null) {
          location.href = "http://bm.qsng.cn/eduplatform/html/api/public/wx/wxOAuth?appId=" + theRequest.appId
        } else {
          var openIds = theRequest.openId.split('#/')
          window.sessionStorage.setItem('openId', openIds[0])
          window.sessionStorage.setItem('studentId', theRequest.studentId)
          window.sessionStorage.setItem('studentName', decodeURIComponent(theRequest.studentName))
          window.sessionStorage.setItem('siteId', theRequest.siteId)
          window.sessionStorage.setItem('userType', theRequest.userType)
          window.sessionStorage.setItem('wxAvatar', theRequest.wxAvatar)
          window.sessionStorage.setItem('appId', theRequest.appId)
          window.sessionStorage.setItem('payOpen', theRequest.payOpen)
          var currentUrl = window.location.href
          var targetUrl = currentUrl.replace(/openId=/, '')
          console.log(targetUrl.replace(/studentId=/, ''))
          window.location.href = targetUrl.replace(/studentId=/, '')
          // history.pushState(null,null,currentUrl)
          // alert(window.location.href)
        }
      }
    },
    goHello (id, name) {
      window.sessionStorage.setItem("areaId", id)
      window.sessionStorage.setItem("areaName", name)
      this.$router.push({
        path: '/Hello',
        query: {
          areaId: id,
          areaName: name
        }
      })
    },
    goBack () {
      window.history.go(-1)
    }
  }
}
